package com.lzcu.maoyan.mapreduce.mapreduce.mapper;

import com.lzcu.maoyan.mapreduce.mapreduce.unit.MovieLeadingActorWritable;
import com.lzcu.maoyan.mapreduce.mapreduce.unit.MovieTypeWritable;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @author WangLiang
 * @date `2024/4/27`
 */
public class MovieLeadingActorMapper extends Mapper<NullWritable, MovieLeadingActorWritable, Text, Text> {
    @Override
    protected void map(NullWritable key, MovieLeadingActorWritable value, Context context)
            throws IOException, InterruptedException {
        String sourceMovieName = value.getSourceMovieName();
        String sourceLeadingActor = value.getSourceLeadingActor();
        long maxTotal = value.getMaxTotal();
        if (sourceLeadingActor != null && !"".equals(sourceLeadingActor)) {
            String[] leadingActorList = sourceLeadingActor.split("／");
            for (String leadingActor : leadingActorList) {
                context.write(new Text(leadingActor), new Text(sourceMovieName + "\001" + String.valueOf(maxTotal)));
            }
        }
    }
}
